package com.schoolvisitors.controller.admin;

import com.alibaba.fastjson2.JSONObject;
import com.schoolvisitors.CheckPermission;
import com.schoolvisitors.dto.CreateTimeSlotDto;
import com.schoolvisitors.enums.PermissionEnum;
import com.schoolvisitors.response.ResultBody;
import com.schoolvisitors.service.TimeSlotService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/admin")
public class TimeSlotController {

    private final TimeSlotService timeSlotService;

    public TimeSlotController(TimeSlotService timeSlotService) {
        this.timeSlotService = timeSlotService;
    }

    @CheckPermission(PermissionEnum.SYSTEM_ADMIN)
    @PostMapping("/createTimeSlot")
    public ResultBody createTimeSlot(@RequestBody @Valid CreateTimeSlotDto createTimeSlotDto){
        timeSlotService.createTimeSlot(createTimeSlotDto);
        return ResultBody.success();
    }

    @CheckPermission(PermissionEnum.SYSTEM_ADMIN)
    @PostMapping("/deleteTimeSlot")
    public ResultBody deleteTimeSlot(@RequestBody JSONObject json){
        Long id = json.getLong("id");
        timeSlotService.deleteTimeSlot(id);
        return ResultBody.success();
    }

    @CheckPermission(PermissionEnum.SYSTEM_ADMIN)
    @GetMapping("/getTimeSlots")
    public ResultBody getTimeSlotRoles(){
        return ResultBody.success(timeSlotService.getAllTimeSlots());
    }
}
